/*
 * CLOCK.c
 *
 * Created: 9/04/2012 3:10:25 PM
 *  Author: Richard
 */ 
#include "CLOCK.h"
#include "SHDL.h"
#include "cdef.h"

ISR(TIMER1_COMPA_vect)
{
	SHDL_vContainter1ms();	
}

void CLOCK_vInit( void )
{
	uint16_bits u16CompareMatch;

	u16CompareMatch.value = ( CLOCK_xCPU_CLOCK_HZ / CLOCK_xTICK_RATE_HZ );
	u16CompareMatch.value /= 64;
	u16CompareMatch.value -= 1;

	OCR1AH = u16CompareMatch.byte.hb;
	OCR1AL = u16CompareMatch.byte.lb;

	TCCR1B = ( 1 << WGM12 ) | ( 1 << CS11 ) | ( 1 << CS10 );
	TIMSK = ( 1 << OCIE1A );
}

void CLOCK_vStopInterrupt( void )
{
	TIMSK &= ~( 1 << OCIE1A );	
}

void CLOCK_vRestartInterrupt( void )
{
	TIMSK |= ( 1 << OCIE1A );	
}

